package com.example.flowabledemo.Test;

import lombok.Cleanup;
import org.flowable.bpmn.converter.BpmnXMLConverter;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.Process;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;

/**
 * @ClassName: TestConctroller
 * @Description:
 * @Date 2024/05/23 09:32
 * @Author songshaoqiu
 **/
@RestController
public class TestConctroller {



    @PostMapping("/test")
    public String test(@RequestBody SaveDto saveDto) throws XMLStreamException {
        BpmnXMLConverter converter = new BpmnXMLConverter();
        InputStream in = new ByteArrayInputStream(saveDto.getBpmnXml().getBytes(StandardCharsets.UTF_8));
        @Cleanup XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(in);
        BpmnModel bpmnModel = converter.convertToBpmnModel(reader);
        List<Process> processes = bpmnModel.getProcesses();
        return "hello";
    }
}
